home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Experimental BBS Explossion 3
/
Experimental BBS Explossion III.iso
/
comunic
/
twft099b.zip
/
TWLAUNCH.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-06-07
|
19KB
|
696 lines
Unit TwLaunch;
{
Copyright (C) 1993 by David Myers. All rights reserved. Personal
copying and use of this code permitted. This source cannot be
sold or distributed for more than the cost of media.
}
interface
uses
Crt,FlyCom,FParser,TwScr,FlyMenu,TwAnsi,TwLine;
const
MaxSectors = 1000;
type
DistType = RECORD
Sector, Distance : Integer;
END;
SectorArray = ARRAY[1 .. MaxSectors] of byte;
MaxDistType = ARRAY[ 1 .. 25] of DistType;
var
MySectors : SectorArray;
ExternSectors : SectorArray;
MaxExtern : integer;
MaxDist : integer;
MaxDistArray : MaxDistType;
Procedure LaunchStuff;
implementation
var
iii : integer;
FUNCTION isdigit( var c : char) : boolean;
{ If the character is a digit, returns TRUE, otherwise returns FALSE }
BEGIN
If ((c >= '0') and (c <= '9')) THEN
isdigit := TRUE
ELSE isdigit := FALSE;
END;
Procedure FindUnknownSectors;
var
i,ec1 : integer;
tokstr, tok2, S : string;
P : ParseType;
toks : integer;
Loopit : Boolean;
temp1, temp2, temp3 : Boolean;
BEGIN
NormalVideo;
tokstr := ' ' +#8+#9+#10+#13;
tok2 := tokstr + '[';
Loopit := TRUE;
for i := 1 to MaxSectors do
MySectors[i] := 0;
Async_Send('C');
REPEAT
GetALine(toks,tokstr,S,'?',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
If Loopit then begin
Async_Send('K');
REPEAT
GetALine(toks,tokstr,S,')',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'(E/U)'));
if Loopit then begin
Async_Send('U');
Async_Send(#13);
REPEAT
GetALine(toks,tok2,S,' ]?',P,Loopit);
if Matchtoken(P.s[toks-1],'Pause]') then
Async_Send(#13);
If (toks > 0) and isdigit(P.s[0][1]) then begin
Val(P.s[0],i,ec1);
if (ec1 = 0) and (i > 0) and (i <= MaxSectors) then
MySectors[i] := 1;
end;
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
Async_Send('Q');
end;
end;
END;
Procedure DisplayStuff;
var
X,Y,YY,j : integer;
c : char;
BEGIN
SaveScreen(X,Y);
SelectWindow(1);
TextColor(Yellow);
TextBackground(Blue);
ClrScr;
Write(' UNKNOWN SECTOR DISPLAY ');
SelectWindow(2);
ClrScr;
j := 0;
While (j < MaxSectors) do begin
Inc(j);
If MySectors[j] > 0 then begin
Write(j : 4);
YY := WhereY;
if YY > 21 then begin
PressEnter(c);
if c = #27 then j := MaxSectors+1;
ClrScr;
end;
end;
end;
PressEnter(c);
RestoreScreen;
NormalVideo;
GotoXY(X,Y);
END;
Procedure LaunchEprobe;
type
PortType = RECORD
Sector, Class : integer;
END;
PortList = ARRAY[1 .. 500] of PortType;
PlanetList = ARRAY[1 .. 100] of integer;
SectorArray = ARRAY[1 .. 26] of String;
var
SA : SectorArray;
tokstr,inputstr,S : string;
index,count : integer;
i,X,Y,YY,low,high,xlow,xhigh,toks,ec1,ec2,temp : integer;
P : ParseType;
Planets, ProbeDeath : Planetlist;
Ports : PortList;
planetcount, portcount, probedeathcount, currentsector : integer;
Loopit, isClassZero,isSeen : Boolean;
BEGIN
Loopit := TRUE;
SaveScreen(X,Y);
tokstr := ' '+#8+#9+#10+#13;
TextColor(LightCyan);
TextBackGround(Blue);
WFrameW(10,5,45,20);
ClrScr;
WriteLn('Enter Sector Numbers of Probes');
WriteLn('An Empty Line Quits');
count := 0;
REPEAT
BuildString(S);
toks := Parse_Str(tokstr,S,P);
if toks = 3 then begin
Val(P.s[0],low, ec1);
Val(P.s[2],high,ec2);
If ((ec1 = 0) and (ec2 = 0)) then begin
if low > high then begin
temp := low;
low := high;
high := temp;
end;
for i := low to high do begin
if (count < 25) then begin
inc(count);
Str(i,SA[count]);
end;
end;
if (count < 25) then begin
YY := WhereY;
GotoXY(12,YY);
WriteLn(' Count : ',count);
end
else WriteLn;
end;
end
else begin
if toks > 0 then begin
if ((P.s[0][1] = 'U') or (P.s[0][1] = 'u')) then begin
low := 1;
S := '';
if (toks > 1) then begin
Val(P.s[1],xlow,ec1);
if (ec1 = 0) then
if xlow < MaxSectors then
low := xlow;
end;
for i := low to MaxSectors do begin
if (MySectors[i] > 0) and (count < 25) then begin
Inc(count);
Str(i,SA[count]);
end;
end;
YY := WhereY;
GotoXY(12,YY);
WriteLn(' Count : ',count);
end
else if ((P.s[0][1] = 'L') or (P.s[0][1] = 'l')) then begin
high := MaxDist;
if (toks = 2) then begin
Val(P.s[1],xhigh,ec1);
if (ec1 = 0) then
if (xhigh > 0) and (xhigh < MaxDist) then
high := xhigh;
end;
if (MaxDist > 0) then
for i := 1 to high do begin
if (count < 25) then begin
Inc(Count);
Str(MaxDistArray[i].Sector,SA[count]);
end;
end;
YY := WhereY;
GotoXY(12,YY);
WriteLn(' Count : ',count);
end
else begin
Inc(count);
SA[count] := S;
YY := WhereY;
GotoXY(12,YY);
WriteLn(' Count : ',count);
end;
end
else WriteLn;
end;
UNTIL((S = '') or (count >= 25));
if (count >= 1) then begin
for i := 1 to count do begin
SA[i] := SA[i] + #13;
end;
WriteLn('---------------------');
WriteLn('Final Count = ',count);
Delay(2000);
RestoreScreen;
SelectWindow(1);
TextColor(White);
TextBackground(Cyan);
ClrScr;
Write(' -----====== ALT-L Eprobe Launch; Alt-Q Quits =====----- ');
SelectWindow(2);
NormalVideo;
GotoXY(X,Y);
index := 1;
planetcount := 0;
portcount := 0;
probedeathcount := 0;
While ((index <= count) and Loopit) do begin
currentsector := 1;
Async_Send('E');
REPEAT
GetALine(toks,tokstr,inputstr,':',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],':'));
If Loopit then begin
Delay(1000);
Async_Send_String(SA[index]);
Inc(index);
REPEAT
GetALine(toks,tokstr,inputstr,'?',P,Loopit);
If (toks = 5) and MatchToken(P.s[0],'Probe') then begin
Val(P.s[4],i,ec1);
if (ec1 = 0) then
currentsector := i;
end;
If MatchToken(P.s[0],'Ports') then begin
{ if we see a port, note it }
if portcount < 1 then begin
ISSEEN := FALSE;
end
else begin
{ record new ports only }
isseen := FALSE;
for i := 1 to portcount do
if Ports[i].Sector = currentsector then
isseen := TRUE;
end;
if NOT isseen then begin
Inc(portcount);
Ports[portcount].Sector := currentsector;
Ports[portcount].Class := Ord(P.s[toks-1][1]) - Ord('0');
end;
end;
If MatchToken(P.s[0],'Probe') and MatchToken(P.s[1],'Destroyed!') then begin
{ note any destroyed probes }
if probedeathcount < 1 then begin
ISSEEN := FALSE;
end
else begin
{ record destruction in new sectors only}
isseen := FALSE;
for i := 1 to probedeathcount do
if ProbeDeath[i] = currentsector then
isseen := TRUE;
end;
if NOT isseen then begin
Inc(probedeathcount);
ProbeDeath[probedeathcount] := currentsector;
end;
end;
If MatchToken(P.s[0],'Planets') then begin
{ record any planets seen }
if planetcount < 1 then begin
ISSEEN := FALSE;
end
else begin
isseen := FALSE;
for i := 1 to planetcount do
if Planets[i] = currentsector then
isseen := TRUE;
end;
if NOT isseen then begin
Inc(planetcount);
Planets[planetcount] := currentsector;
end;
end;
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'=Help)?'));
end;
end;
if probedeathcount > 0 then begin
SaveScreen(X,Y);
TextColor(White);
TextBackGround(Blue);
WFrameW(10,5,45,20);
ClrScr;
WriteLn('Probes Died in These Sectors: ');
for i := 1 to probedeathcount do
WriteLn(ProbeDeath[i]);
WriteLn('-----------------------');
WriteLn('Press ENTER to continue');
ReadLn(S);
SelectWindow(2);
RestoreScreen;
NormalVideo;
GotoXY(X,Y);
end;
if (planetcount > 0) then begin
SaveScreen(X,Y);
TextColor(Yellow);
TextBackGround(Blue);
WFrameW(10,5,45,20);
ClrScr;
WriteLn('Planets Found in These Sectors: ');
for i := 1 to planetcount do
WriteLn(Planets[i]);
WriteLn('-----------------------');
WriteLn('Press ENTER to continue');
ReadLn(S);
SelectWindow(2);
RestoreScreen;
NormalVideo;
GotoXY(X,Y);
end;
isClassZero := FALSE;
if (portcount > 0) then
for i := 1 to portcount do
if (Ports[i].Class = 0) then
isClassZero := TRUE;
if isClassZero then begin
SaveScreen(X,Y);
TextColor(White);
TextBackGround(Red);
WFrameW(10,5,45,12);
ClrScr;
WriteLn('Class Zero Ports Found: ');
for i := 1 to portcount do
if Ports[i].Class = 0 then
WriteLn(Ports[i].Sector);
WriteLn('-----------------------');
WriteLn('Press ENTER to continue');
ReadLn(S);
SelectWindow(2);
RestoreScreen;
NormalVideo;
GotoXY(X,Y);
end;
end { if count }
else begin
RestoreScreen;
SelectWindow(2);
NormalVideo;
GotoXY(X,Y);
end;
TopLine;
SaveScreen(X,Y);
TextColor(Yellow);
TextBackground(GREEN);
GoToXY(10,10);WriteLn(' ');
GoToXY(10,11);WriteLn(' Exiting EPROBE Macro ');
GoToXY(10,12);WriteLn(' ');
Delay(2000);
NormalVideo;
RestoreScreen;
GoToXY(X,Y);
END;
Procedure FindMaxDist;
var
i,j, jj,maxj,X,Y : integer;
S : string;
dist : integer;
c : char;
toks : integer;
P : ParseType;
tokstr : string;
Loopit,Done : Boolean;
BEGIN
X := WhereX; Y := WhereY;
SelectWindow(1);
TextColor(WHITE);
TextBackGround(Green);
ClrScr;
Write(' ===== Finding Longest Eprobe Distances. ALT-Q Quits ===== ');
SelectWindow(2);
NormalVideo;
GotoXY(X,Y);
for i := 1 to 25 do begin
MaxDistArray[i].Distance := 0;
MaxDistArray[i].Sector := 0;
end;
Loopit := TRUE;
tokstr := ' >' +#8+#9+#10+#13;
j := 0;
MaxDist := 0;
Async_Send('C');
REPEAT
GetALine(toks,tokstr,S,'?',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
While (j < MaxSectors) do begin
Inc(j);
If MySectors[j] > 0 then begin
Async_Send('F');
REPEAT
GetALine(toks,tokstr,S,'?',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
if Loopit then begin
Async_Send(#13);
REPEAT
GetALine(toks,tokstr,S,'?',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'sector?'));
if Loopit then begin
Str(j,S);
S := S + #13;
Async_Send_String(S);
REPEAT
GetALine(toks,tokstr,S,':',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'is:'));
if Loopit then begin
dist := 0;
REPEAT
GetALine(toks,tokstr,S,' ?',P,Loopit);
{ LastAttr is a global variable created by the ansi driver
to save the previous screen attributes }
If isdigit(P.s[0][1]) then
if ((TextAttr and 15) = LightRed) or
((LastAttr and 15) = LightRed) then
inc(dist);
If MatchToken(P.s[toks-1],'Avoids?') then begin
{ this "if" should work but it doesn't..}
Delay(2500);
Async_Send('N');
Async_Send(#13);
end;
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
if Loopit then begin { #4 }
if (dist > 0) then begin
Done := FALSE;
if (MaxDist <= 0) then begin
Inc(MaxDist);
MaxDistArray[1].Distance := dist;
MaxDistArray[1].Sector := j;
end
else if (MaxDist < 25) then begin
i := 0;
While ( i < MaxDist) and (NOT Done) do begin
Inc(i);
if (dist > MaxDistArray[i].Distance) then begin
Done := TRUE;
for jj := MaxDist+1 downto i+1 do begin
MaxDistArray[jj].Distance := MaxDistArray[jj-1].Distance;
MaxDistArray[jj].Sector := MaxDistArray[jj-1].Sector;
end;
MaxDistArray[i].Distance := Dist;
MaxDistArray[i].Sector := j;
Inc(MaxDist);
end;
end;
if NOT Done then begin
Inc(MaxDist);
MaxDistArray[MaxDist].Distance := Dist;
MaxDistArray[MaxDist].Sector := j;
end;
end
else begin
i := 0;
Done := FALSE;
While ( i < MaxDist) and NOT Done do begin
Inc(i);
if dist > MaxDistArray[i].Distance then begin
Done := TRUE;
for jj := MaxDist downto i+1 do begin
MaxDistArray[jj].Distance := MaxDistArray[jj-1].Distance;
MaxDistArray[jj].Sector := MaxDistArray[jj-1].Sector;
end;
MaxDistArray[i].Distance := Dist;
MaxDistArray[i].Sector := j;
Inc(MaxDist);
end;
end;
end;
end;
end; { loopit #4 }
end; { loopit #3 }
end; { loopit #2 }
end; { loopit #1 }
end;
end;
Async_Send('Q');
TopLine;
SaveScreen(X,Y);
TextColor(Yellow);
TextBackground(Red);
WFrameW(5,5,45,22);
ClrScr;
WriteLn(' The Longest Eprobe Shots Are:');
If MaxDist > 0 then begin
maxj := MaxDist;
if maxj > 12 then maxj := 12;
for j := 1 to maxj do
WriteLn('Sector ',MaxDistArray[j].Sector,
' Dist: ',MaxDistArray[j].Distance);
end;
WriteLn('-----------------');
WriteLn('Press ENTER ');
REPEAT
c := ReadKey;
UNTIL ((c = #13) or (c = #27));
RestoreScreen;
SelectWindow(2);
NormalVideo;
GotoXY(X,Y);
END;
Procedure LaunchDisruptors;
var
toks : integer;
tokstr,S, sector : string;
P : ParseType;
nummines : integer;
Loopit, Done : Boolean;
X, Y, index : integer;
BEGIN
tokstr := ' '+#8+#9+#10+#13;
SaveScreen(X,Y);
TextColor(White);
TextBackground(Blue);
WFrameW(5,5,45,10);
ClrScr;
WriteLn(' TWFT Mine Disruptor Launch ');
Write(' Sector to launch into : ');
BuildString(sector);
if (sector <> '') then begin
sector := sector + #13;
Write(' Number of disruptors : ');
ReadLn(nummines);
RestoreScreen;
SelectWindow(1);
TextColor(White);
TextBackground(Green);
ClrScr;
Write(' ----- ===== +++++ Mine Disruptor Macro - ALT-Q quits +++++ ===== ----- ');
SelectWindow(2);
NormalVideo;
GotoXY(X,Y);
Loopit := TRUE;
Async_Send('C');
REPEAT
GetALine(toks,tokstr,S,'?',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
index := 0;
Done := FALSE;
While Loopit and (index < nummines) and (NOT Done) do begin
Inc(index);
Async_Send('W');
REPEAT
GetALine(toks,tokstr,S,'?',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
Async_Send('Y');
if Loopit then begin
REPEAT
GetALine(toks,tokstr,S,')',P,Loopit);
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'quit)'));
if Loopit then begin
Async_Send_String(sector);
REPEAT
GetALine(toks,tokstr,S,'?',P,Loopit);
if (toks > 3) then begin
If MatchToken(P.s[2],'all') then
Done := TRUE;
If MatchToken(P.s[2],'no') then
Done := TRUE;
end;
UNTIL ((NOT Loopit) or MatchToken(P.s[toks-1],'?'));
end;
end;
end; { while }
if Loopit then
Async_Send('Q');
TopLine;
end { if sector <> '' }
else begin
RestoreScreen;
SelectWindow(2);
NormalVideo;
GotoXY(X,Y);
end;
SaveScreen(X,Y);
TextColor(Yellow);
TextBackground(Red);
GoToXY(10,10);WriteLn(' ');
GoToXY(10,11);WriteLn(' Exiting MINE DISRUPTOR Macro ');
GoToXY(10,12);WriteLn(' ');
Delay(2000);
NormalVideo;
RestoreScreen;
GoToXY(X,Y);
END;
Procedure LaunchStuff;
var
X,Y : integer;
c : char;
BEGIN
SaveScreen(X,Y);
REPEAT
TextColor(LightRed);
TextBackGround(Black);
ClrScr;
GotoXy(22,5); Write('Tradewars Freeware Terminal Launch Menu');
TextColor(Cyan);
GotoXy(1,10);Write('A. Eprobe Launch ');
GotoXy(1,11);Write('B. Collect Unknown Sectors');
GotoXy(1,12);Write('C. Display Unknown Sectors');
GotoXy(1,13);Write('D. Find Longest Distances');
GotoXy(1,14);Write('E. Mine Disruptor Launch');
GotoXy(1,15);Write('X. Exit');
TextColor(LightRed);
GoToXY(1,16);
c := ReadKey;
c := UpCase(c);
Case c of
'A' : BEGIN
RestoreScreen;
GotoXY(X,Y);
LaunchEprobe;
SaveScreen(X,Y);
END;
'B' : BEGIN
RestoreScreen;
GotoXY(X,Y);
FindUnknownSectors;
SaveScreen(X,Y);
END;
'C' : BEGIN
RestoreScreen;
GotoXY(X,Y);
DisplayStuff;
SaveScreen(X,Y);
END;
'D' : BEGIN
RestoreScreen;
GotoXY(X,Y);
FindMAxDist;
SaveScreen(X,Y);
END;
'E' : BEGIN
RestoreScreen;
GotoXY(X,Y);
LaunchDisruptors;
SaveScreen(X,Y);
END;
else;
end; { case }
UNTIL ((c = 'X') or (c = #27));
RestoreScreen;
NormalVideo;
GotoXY(X,Y);
END;
BEGIN { unit initialization code }
for iii := 1 to MaxSectors do begin
MySectors[iii] := 0;
ExternSectors[iii] := 0;
end;
MaxDist := 0;
MaxExtern := 0;
END.